package com.linxz.wandnroid.adapter;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.linxz.wandnroid.appui.ArticleFragment;
import com.linxz.wandnroid.appui.ProjectFragment;
import com.linxz.wandnroid.appui.SystemFragment;
import com.linxz.wandnroid.enums.CHANNEL;


/**
 * @author Linxz
 * 创建日期：2020年02月20日 23:22
 * version：v4.5.4
 * 描述：
 */
public class HomePagerAdapter extends FragmentPagerAdapter {

    private CHANNEL[] channels;


    public HomePagerAdapter(FragmentManager fm, CHANNEL[] channels) {
        super(fm);
        this.channels = channels;
    }

    @Override
    public Fragment getItem(int position) {
        CHANNEL channel = channels[position];
        switch (channel) {
            case ARTICLE:
                return ArticleFragment.newInstance();
            case PROJECTS:
                return ProjectFragment.newInstance();
            case SYSTEM:
                return SystemFragment.newInstance();
            default:
                break;
        }
        return null;
    }

    @Override
    public int getCount() {
        return channels == null ? 0 : channels.length;
    }
}
